// mine/pages/platformclass/index.js
const $class = require("../../../api/class").API

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl:"https://img.yzcdn.cn/vant/cat.jpeg",
    sign_year:new Date().getFullYear(),
    sign_month:new Date().getMonth(),
    sign_day:new Date().getDate(),
    currentDate: new Date().getTime(),
    minDate: new Date().getTime(),
    showchoosetime:false,
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
    type:2,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var t = this
    t.setData({
      type:options.type
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var t = this
    t.getInsClassList()
  },

  gotoattendance(e){
    var t = this
    console.log(e)
    wx.navigateTo({
      url:'/pages/class/deanattendance/index?type='+t.data.type + '&class_id=' + e.currentTarget.dataset.id + '&currentDate=' + t.data.currentDate
    })
  },
  onClose(){
    var t= this
    t.setData({
      showchoosetime:false
    })
  },
  choosetime(){
    var t= this
    t.setData({
      showchoosetime:true
    })
  },
  choosed(e){
    var t = this
    t.setData({
      showchoosetime:false
    })
    console.log("选择时间确定choosed")
    // t.getInsAttendanceList()

  },
  timechange(e){
    var t= this
    console.log(e)
    var time = e.detail
    if (time) {
      var oDate = new Date(time * 1),
        oYear = oDate.getFullYear(),
        oMonth = oDate.getMonth() + 1,
        oDay = oDate.getDate()
        t.setData({
          sign_year:oYear,
          sign_month:oMonth,
          sign_day : oDay,
          currentDate:time,
        })
    }
  },
  // 根据机构ID获取班级列表
  getInsClassList(){
    var t = this,
    data = {
      institution_id:wx.getStorageSync('TeacherClassinfo').institution_id,
    }
    $class.getInsClassList(data).then(res=>{
      t.setData({
        classlists:res.data
      })
    })
  }
})